#include "filter.h"

double Filter::filtered_value(double new_data) {
  double ret;
  if (cnt < 4) { //前4个不滤波
    data[cnt++] = new_data; 
    ret = new_data;
  } else {   
    cnt++;
    //数据模型：a,b,c,d,new_data;
    data[4] = new_data; //存入新数据
    double weighted_sum = 0;
    for (int k = 0; k < 5; k++)
      weighted_sum += data[k] * weight[k] / 100.0;
    data_move_left(); //数据左移
    ret = weighted_sum;
  }
  return ret;
}